﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dbPoll_Application.Models.RankingQuestion>" validateRequest="false" %>
<%@ Import Namespace="dbPoll_Application.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Edit Ranking Question
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="pageHeadingContainer"><h2 class="pageHeading">Question Editor</h2></div>
    <div id="contentContainer"> 
        <p>
           <%= Html.ActionLink("Polls > ", "Index", "Poll", null, new { @class = "breadcrumb" })%>
           <%= Html.ActionLink(ViewData["pollName"] + " > ", "Questions", "Poll", new { pollID = ViewData["pollID"], pollName = ViewData["pollName"] }, new { @class = "breadcrumb" })%>
           Question <%= Model.questionNumber %>
        </p>
    <script src="../../Scripts/EditMCQ.js" type="text/javascript"></script>
    
    <% Html.EnableClientValidation();
       var pollRoles = ViewData["pollRoles"] as ICollection<dbPoll_Application.Models.Role>;
       var pollCreator = new dbPoll_Application.Models.Role("Poll Creator");
       var pollAdministrator = new dbPoll_Application.Models.Role("Poll Administrator");
       DateTime? pollClose = ViewData["pollClose"] as DateTime?;
       DateTime? pollStart = ViewData["pollStart"] as DateTime?;
    %>
        <% if (Model.questionID < 0)
       {
           Html.RenderPartial("PageMenu", Model);
       } %>
    <% String actionName;
       if (Model.questionID < 0)
       {
           actionName = "AddRanking";
       }
       else {
           actionName = "UpdateRanking";
       } %>
    <%  using (Ajax.BeginForm(actionName, new AjaxOptions { OnSuccess = "onSubmitSuccess" }))
        { %>
       <input type="hidden" id="pollID" value="<%= ViewData["pollID"] %>" name="pollID" />
       <input type="hidden" id="pollName" value="<%= ViewData["pollName"] %>" name="pollName" />   
       <% Html.RenderPartial("Question", Model); %>
       
       <div id="rightColumn">
           <div class="right">
               <ul class="rightColumnList" id="objectSettingsList">
                   <li class="rightColumnListHeading"><h2>Rank Values</h2></li>
                   <li class="rightColumnListItem">
                       <table id="rankTable">
                           <tr><th>Rank</th><th>Value</th></tr>
                           <% for (int i = 0; i < Model.rankValues.Count; i++)
                           { %>
                           <tr id="<%=i %>"><td><%= i + 1 %></td><td><%= Html.HiddenFor(m => m.rankValues[i].rankValueID) %><%= Html.TextBoxFor(m => m.rankValues[i].value, new { @class = "rankValue" })%></td></tr>  
                           <% } %>
                       </table>
                   </li>
               </ul>
           </div>
           <% Html.RenderPartial("QuestionObjects", Model); %>
           <% Html.RenderPartial("QuestionSettings", Model); %>
           <% Html.RenderPartial("ChartSettings", Model); %>
       </div>
       <div class="compareWith">
           <%= Html.HiddenFor(m => m.compareWith.questionID)%>
           <span class="left">Compare with:</span>
           <% var compareWith = ViewData["compareWith"] as String; %>
           <span class="searchCompareWith"><%= compareWith.CropAndTrail(40, "...") %></span>
           <span class="searchXCompareWith"><input type="button" value="Search" id="searchCompareQuestion" /></span>
           <span class="deleteCompareWith"><input type="button" value="Clear" id="clearCompareQuestion" /></span>
           <span>display chart 
           <%= Html.CheckBoxFor(m => m.comparisonChart.active)%></span>
           <%= Html.HiddenFor(m => m.comparisonChart.chartID)%>
           <%= Html.HiddenFor(m => m.comparisonChart.chartType)%>
           <%= Html.HiddenFor(m => m.comparisonChart.valueType)%>
           <%= Html.HiddenFor(m => m.comparisonChart.colours)%>
       </div>
       <div class="clear"></div>
       <% } %>
       </div>
    <script type="text/javascript" >
       <%  for (int a=0; a<5-Model.allowedAnswers; a++)
           {%>
               document.getElementById("<%=4-a%>").style.display='none';
         <%}      
       if  (!(pollRoles.Contains(pollCreator) || pollRoles.Contains(pollAdministrator)) || pollStart!=null) 
       {%> document.getElementById("question").readOnly=true;
       <%  int it=0;
           foreach (var options in Model.options) 
           {%>
               document.getElementById("options_<%=it%>__answer").readOnly=true;
               if ("<%=Model.rankValues.Count>it%>"=="True")
               {
                   document.getElementById("rankValues_<%=it%>__value").readOnly=true;
               }
               if ("<%= pollClose>DateTime.Now%>"=="True")
               {
                   document.getElementById("options_<%=it%>__pointsCurrent").readOnly=true;
                   document.getElementById("options_<%=it%>__correctCurrent").disabled=true;
                   document.getElementById("allowedAnswers").disabled=true;
               }
               <%it++;
           }
       } %>
       $(document).ready(function() {
        $('#allowedAnswers').change(function() {
            var number =  $('#allowedAnswers').val();
            for (var a=0; a<5; a++) 
            {
                document.getElementById(a).style.display='none';
            }
            for (var i=0; i<number;i++) 
            {
                document.getElementById(i).style.display='table-row';
            }
        });
       });
    </script>
</asp:Content>